using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Acms.SqlDal;

namespace Acms.Bll
{
    public class UserPostComment : BaseItem
    {
        protected UserPostComment() : base() { }
        protected UserPostComment(Hashtable table) : base(table) { }
        protected UserPostComment(Hashtable table, List<UserPostComment> collection) : base(table, collection) { }

        public static UserPostComment CreateInstance(int userId, int postId, System.Net.IPAddress ipAddress)
        {
            UserPostComment tmp = new UserPostComment();
            tmp.userId = userId;
            tmp.postId = postId;
            tmp.ipAddress = ipAddress;
            return tmp;
        }

        protected override Base CreateDal()
        {
            return new UserPostCommentDal();
        }

        private static UserPostComment Get(Hashtable table)
        {
            if (table != null)
            {
                return new UserPostComment(table);
            }
            else
            {
                return null;
            }
        }

        private static List<UserPostComment> Get(Hashtable[] tables)
        {
            if (tables != null)
            {
                List<UserPostComment> tmp = new List<UserPostComment>();
                foreach (Hashtable table in tables)
                {
                    tmp.Add(new UserPostComment(table, tmp));
                }
                return tmp;
            }
            else
            {
                return null;
            }
        }

        public static UserPostComment GetById(int id)
        {
            UserPostCommentDal dal = new UserPostCommentDal();
            return Get(dal.GetById(id));
        }

        public static List<UserPostComment> GetAllByPostId(int postId)
        {
            UserPostCommentDal dal = new UserPostCommentDal();
            return Get(dal.GetAllByPostId(postId));
        }

        public new void Update()
        {
            base.Update();
        }

        protected override void SaveChanges(ref object concurencyId, Base dal)
        {
            if (IsNewRecord)
            {
                created = DateTime.Now;
            }
            ((UserPostCommentDal)dal).Update(ref id, userId, ref userName, postId, title, comment, ipAddress, reviewed, reported, suspended, created, ref concurencyId);
        }

        protected override void Load(Hashtable table)
        {
            id = (int)table[UserPostCommentDal.Fields.Id];
            userId = (int)table[UserPostCommentDal.Fields.UserId];
            userName = (string)table[UserPostCommentDal.Fields.UserName];
            postId = (int)table[UserPostCommentDal.Fields.PostId];
            title = (string)table[UserPostCommentDal.Fields.Title];
            comment = (string)table[UserPostCommentDal.Fields.Comment];
            ipAddress = (System.Net.IPAddress)table[UserPostCommentDal.Fields.IPAddress];
            reviewed = (bool)table[UserPostCommentDal.Fields.Reviewed];
            reported = (bool)table[UserPostCommentDal.Fields.Reported];
            suspended = (bool)table[UserPostCommentDal.Fields.Suspended];
            created = (DateTime)table[UserPostCommentDal.Fields.Created];
        }

        private int id;
        public int Id
        {
            get { return id; }
        }

        private int userId;
        public int UserId
        {
            get { return userId; }
        }

        private string userName;
        public string UserName
        {
            get { return userName; }
        }
	

        private int postId;
        public int PostId
        {
            get { return postId; }
        }

        private string title;
        public string Title
        {
            get { return title; }
            set { title = value; }
        }

        private string comment;
        public string Comment
        {
            get { return comment; }
            set { comment = value; }
        }

        private System.Net.IPAddress ipAddress;
        public System.Net.IPAddress IPAddress
        {
            get { return ipAddress; }
        }
        

        private bool reviewed;
        public bool Reviewed
        {
            get { return reviewed; }
            set { reviewed = value; }
        }

        private bool reported;
        public bool Reported
        {
            get { return reported; }
            set { reported = value; }
        }

        private bool suspended;
        public bool Suspended
        {
            get { return suspended; }
            set { suspended = value; }
        }

        private DateTime created;
        public DateTime Created
        {
            get { return created; }
        }	

    }
}
